#!/bin/sh

# 注入环境变量
. $CI_SHELL_PATH/scripts/build-env-generate.sh

set +xe

# 备份 html 版本

project_name=$1

addVersion(){
    echo "$1 - $2 - $3 - $4"
    # 上报备份 id
    curl -H "Content-type:application/json; charset=UTF-8" -X POST -d '{
      "version": "'$1'",
      "project": "'$2'",
      "env": "'$3'"
    }' https://$4/qtrade_ums/api/frontend/rollback/add
}

# 如果存在
if [ ! -z "$ROLLBACK_VERSION_ID" ]; then
  # 上报备份 id
	if [ $SENTRY_ENV = 'dev' ]; then
		addVersion $ROLLBACK_VERSION_ID $project_name $SENTRY_ENV dev.qtrade.com.cn
  elif [ $SENTRY_ENV = "qa" ]; then
		addVersion $ROLLBACK_VERSION_ID $project_name $SENTRY_ENV real-test.qtrade.com.cn
  elif [ $SENTRY_ENV = "uat" ]; then
    addVersion $ROLLBACK_VERSION_ID $project_name $SENTRY_ENV test.qtrade.com.cn
  elif [ $SENTRY_ENV = "prl" ]; then
    addVersion $ROLLBACK_VERSION_ID $project_name $SENTRY_ENV prl.qtrade.com.cn
  elif [ $SENTRY_ENV = "production" ]; then
    addVersion $ROLLBACK_VERSION_ID $project_name $SENTRY_ENV www.qtrade.com.cn
	fi
fi
